<?php
namespace app\common\behavior;
use app\common\util\DBUtil;
use Request;
class AdminLog {
	public function run($params) {
		$request =  Request::instance();
		$url = strtolower($request->module()."/".$request->controller()."/".$request->action());

		$reqParams = $request->param();
		$p = array();
		foreach($reqParams as $key => $v){
			if(is_string($v)) {
				$p[$key] = mb_substr($v, 0, 200);
			} else {
				$p[$key] = $v;
			}
		}
		$user = session('user');
		if(!$user) {
			return;
		}
		$username = $user['username'];
		$data = [
			// 'uid'		=> session('uid')?:0,
			'username'	=> $username,
			'ip'		=> $request->ip(),
			'action'	=> $url,
			'content'   => json_encode($p),
			'log_time'	=> time(),
		];
		DBUtil::connect_admin()->table('admin_action_log')->insert($data);
	}


}